//
//  BuleFuction.h
//  BlueToothDemo
//
//  Created by Jeamine on 16/1/21.
//  Copyright © 2016年 Jeamine. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

@interface BuleFuction : NSObject
@property(nonatomic,assign)BOOL isSecond;

/*
 功能：获取锁的aeskey
 */
+(void)doGetAESKeywith:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic;

/*
 功能：锁主开锁
 */
+(void)doOpenLock:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic*)characteristic withRSApublickeKey:(NSString *)rsaPublic ;

/*
 功能：校时
 */
+(void)checkoutTime:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic*)characteristic withRSApublickeKey:(NSString *)rsaPublic;

#pragma mark - 打包校时
+(NSData *)packageCheckTimeToDataWithRsaPublickey:(NSString *)rsaPublicKey userAESKey:(NSString *)AESKeyCode;

#pragma mark - 委托校时
+(void)accreditDoCheckTime:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic withData:(NSData *)RSAData lastAESPackage:(NSData *)lastAESPackage;

/*
 功能：设置黑名单
 */
+(void)settingBlackList:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic withRSApublickeKey:(NSString *)rsaPublic blackMobile:(NSString *)mobile;

#pragma mark - 打包设置黑名单指令包
+(NSData *)packageSettingBlackUserWithPhone:(NSString *)phoneNumber psaPublicKey:(NSString *)rsaPublicKey userAESKey:(NSString *)AESKeyCode;

#pragma mark - 委托设置黑名单
+(void)accreditDoSettingBlackUser:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic withData:(NSData *)RSAData lastAESPackage:(NSData *)lastAESPackage;

/*
 功能：取消黑名单
 */
+(void)cancelBlackList:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic withRSApublickeKey:(NSString *)rsaPublic blackMobile:(NSString *)mobile;

#pragma mark - 打包取消黑名单指令包
+(NSData *)packageCancelBlackUserWithPhone:(NSString *)phoneNumber psaPublicKey:(NSString *)rsaPublicKey userAESKey:(NSString *)AESKeyCode;

#pragma mark - 委托取消设置黑名单
+(void)accreditDoCancelBlackUser:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic withData:(NSData *)RSAData lastAESPackage:(NSData *)lastAESPackage;

/*
 功能：子钥匙开锁
 */
+(void)accreditDoOpenLock:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic*)characteristic withData:(NSData *)RSAData lastAESPackage:(NSData *)lastAESPackage;

/*
 功能 ：打包子钥匙数据包
 */
+ (NSData *)packChildkeyToData:(NSString *)rsaPublicKey mobileStr:(NSString *)phone startTime:(NSString *)startTime endTime:(NSString *)endTime commondCode:(NSString *)commondCode userAESKey:(NSString *)AESKeyCode;

#pragma mark - 读取锁内信息
+(void)readLockMessage:(NSData *)AesKey andPrigher:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic withRSApublickeKey:(NSString *)rsaPublic;

#pragma mark - 更换锁芯
/**
 更换锁芯
 
 @param AesKey 从锁第一次返回数据中截取出来,给最外层数据加密
 @param peripheral 蓝牙锁
 @param characteristic 锁包含的信息
 @param rsaPublicKey 锁主公钥，用于加密中间的RSA数据
 */
+ (void)changeLockCore:(NSData *)AesKey andPeripheral:(CBPeripheral *)peripheral andCharacteristic:(CBCharacteristic *)characteristic andRSAPublicKey:(NSString *)rsaPublicKey;

#pragma mark 5-3 设置密码
+(void)settingPassword:(NSData *)AesKey andPeripheral:(CBPeripheral *)peripheral and:(CBCharacteristic *)characteristic withRSApublickeKey:(NSString *)rsaPublic password:(NSString *)pwd;


#pragma mark 5-11 开锁密码 工具方法
/**6位[0--10]的随机数*/
+ (NSString *)sixRandomStr;
/**12字节随机开锁密码:前六字节开锁密码，后六字节后填充0*/
+ (NSData *)twelveUnlockpwdWithSixRandomStr:(NSString *)sixRanStr;

@end
